package com.zhang.gulimall.product.service.impl;

import com.mysql.cj.util.StringUtils;
import com.zhang.gulimall.product.entity.AttrGroupEntity;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhang.gulimall.common.utils.PageUtils;
import com.zhang.gulimall.common.utils.Query;

import com.zhang.gulimall.product.dao.BrandDao;
import com.zhang.gulimall.product.entity.BrandEntity;
import com.zhang.gulimall.product.service.BrandService;


@Service("brandService")
public class BrandServiceImpl extends ServiceImpl<BrandDao, BrandEntity> implements BrandService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<BrandEntity> page = this.page(
                new Query<BrandEntity>().getPage(params),
                new QueryWrapper<>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils queryBasePage(Map<String, Object> params) {
        String key = (String) params.get("key");
        if (key.isEmpty()){
            return queryPage(params);
        } else {
            QueryWrapper<BrandEntity> wrapper = new QueryWrapper<>();
            String keys = (String) params.get("key");
            if (!StringUtils.isEmptyOrWhitespaceOnly(key)){
                wrapper.lambda().like(BrandEntity::getBrandId, key).or().like(BrandEntity::getName,keys).or().like(BrandEntity::getDescript,keys);
            }
            return new PageUtils(this.page(new Query<BrandEntity>().getPage(params),wrapper));
        }
    }
}